<!-- 
    @author Wójcik Karol <wojcikk@student.agh.edu.pl>
    @licence http://www.gnu.org/copyleft/gpl.html GNU/GPL
-->

<div id="colOne">
&nbsp;
</div>
<div id="colTwo">
Raporty indywidualne:
<ul >
<% for f in @fac %>
<li style="display:inline;padding:10px;"><%= link_to f.name, :action => 'index', :facultie => f.id %></li>

<% end %>
</ul>
<%= start_form_tag :action => 'index' %>
<table border='0' cellpadding='5'>
<tr><td><%= check_box_tag "columns[]", "class_type", @columns.include?("class_type") %> Typ zajec </td></tr>
<tr><td><%= check_box_tag "columns[]", "name", @columns.include?("name") %> Imie </td></tr>
<tr><td><%= check_box_tag "columns[]", "surname", @columns.include?("surname") %> Nazwisko </td></tr>
<tr><td><%= check_box_tag "columns[]", "lgrzaj", @columns.include?("lgrzaj") %> LGrZaj </td></tr>
<tr><td><%= check_box_tag "columns[]", "lgrroz", @columns.include?("lgrroz") %> LGrRoz </td></tr>
<tr><td><%= check_box_tag "columns[]", "lgodznazaj", @columns.include?("lgodznazaj") %> LGodzNaZaj </td></tr>
<tr><td><%= check_box_tag "columns[]", "lgodzin", @columns.include?("lgodzin") %> LGodzin </td></tr>
<tr><td><%= check_box_tag "columns[]", "sums", @columns.include?("sums") %> Podsumowanie </td></tr>
<tr><td><%= submit_tag 'Wybierz' %> </td></tr>
</table>

<%= end_form_tag %>

<% 
major=''
subject=''
semestr=''
%>
<table border='0' width='80%' CELLPADDING='5'>

<% 	
keys=@out.keys
suma=0
for k in 0...keys.length
semestr=''	
	
	subkey=@out[keys[k]].keys
	total=0
	for j in 0...subkey.length
		
		suma=0
		for z in @out[keys[k]][subkey[j]]
			suma+=Integer(z.lesson.lgodznazaj)*Integer(z.lgrroz)*Float(z.lesson.class_type.ratio)
			if major!=z.lesson.subject.major.name
				major=z.lesson.subject.major.name
				%>
				<tr><td colspan='9' style="background:#EEE8CD;height:50px;"><h1><%=z.lesson.subject.major.faculty.name%> - <%=major%></h1></td></tr>
			
				<%
			end
			if subject!=z.lesson.subject.name
				subject=z.lesson.subject.name
				%>
				<tr><td colspan='9' style="height:50px;">&nbsp;</td></tr>
				<tr style="background:#EEE8CD;"><td colspan='2'><h4>&nbsp;&nbsp;<%=subject%></h4></td><td><h4>Rok:<%=z.lesson.subject.year%></h4></td></tr>
			<%
			end
			if semestr!=subkey[j]
				semestr=subkey[j]
				
				%>
				<tr><td colspan='9' style="height:20px;">&nbsp;</td></tr>
				<tr><td colspan='9'><h4>&nbsp;&nbsp;<%=semestr%></h4></td></tr>
		<tr style="background:#CDC8B1;">
			<td WIDTH='30px' >&nbsp;</td>
			<% if @columns.include?("class_type")%>
			<td WIDTH='30px'>Typ Zajec</td>
			<% end %>
			<% if @columns.include?("surname")%>
			<td WIDTH='100px' >Nazwisko</td>
			<% end %>
			<% if @columns.include?("name")%>
			<td WIDTH='70px' >Imie</td>
			<% end %>
			<% if @columns.include?("lgrzaj")%>
			<td WIDTH='20px' >LGrZaj</td>
			<% end %>
			<% if @columns.include?("lgrroz")%>
			<td WIDTH='20px' >LGrRoz</td>
			<% end %>
			<% if @columns.include?("lgodznazaj")%>
			<td WIDTH='20px' >LGodzNaZaj</td>
			<% end %>
			<% if @columns.include?("lgodzin")%>
			<td WIDTH='20px' >LGodzin</td>
			<% end %>

		</tr>
				<%
			end
			total+=suma
			
			
			
		
	%>
	<tr>
	
			<td WIDTH='30px' >&nbsp;</td>
			<% if @columns.include?("class_type")%>
			<td WIDTH='30px'><%=z.lesson.class_type.name %></td>
			<% end %>
			<% if @columns.include?("surname")%>
			<td WIDTH='100px' ><%= z.user.surname %></td>
			<% end %>
			<% if @columns.include?("name")%>
			<td WIDTH='70px' ><%= z.user.name %></td>
			<% end %>
			<% if @columns.include?("lgrzaj")%>
			<td WIDTH='20px' ><%=z.lesson.lgrzaj %></td>
			<% end %>
			<% if @columns.include?("lgrroz")%>
			<td WIDTH='20px' ><%=z.lgrroz %></td>
			<% end %>
			<% if @columns.include?("lgodznazaj")%>
			<td WIDTH='20px' ><%=z.lesson.lgodznazaj %></td>
			<% end %>
			<% if @columns.include?("lgodzin")%>
			<td WIDTH='20px' ><%=Integer(z.lesson.lgodznazaj)*Integer(z.lgrroz)*Float(z.lesson.class_type.ratio)%></td>
			<% end %>

		</tr>
	<% end %>
	<tr><td colspan='9'>
			<% if @columns.include?("sums") and semestr!=''%>
			<table style="border:solid 1px;" align='right' CELLPADDING='10'><tr>
			
					<td style="border:solid 1px;">PARTIAL: <br><center>
					
					<%= suma%></center></td>
			
			</tr></table>
			<% end %>
		</td></tr>
	<%end 
	%>
	<tr><td colspan='9'>
			<% if @columns.include?("sums") and semestr!=''%>
			<table style="width:100%;text-align:right;border:solid 1px;" align='right' CELLPADDING='10'><tr>
			
					<td style="border:solid 1px;">TOTAL: <br>
					
					<%= total %></td>
			
			</tr></table>
			<% end %>
		</td></tr>
	<%
	end%>	
</table>
</div>